﻿<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="/easyui/demo.css">
	<link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />

    <style>
        @media screen{
            #canvas{
                display: none;
            }
            #image{
                display: none;
            }
        }
        @media print{
            #canvas{
                display: none;
            }
            #image{
                display: block;
            }
        }
    </style>
	<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>

</head>
<body class="easyui-layout">
<div data-options="region:'center',border:false" style="padding: 2px;height: auto">
	<div class="easyui-layout" id="conent-layout" style="width:100%;height:100%;">
		<div data-options="region:'center'" title="HTTP服务信息">
			<table id="tt" class="easyui-datagrid" ,style="width:100%;height:99%;"
				   data-options="fit:true, rownumbers:true, pagination:true,singleSelect:true,url:'<%=basePath%>/warehouse-manage-json/InPlanMainEntity',
           	   method:'get',
           	   fitColumns : 'true',
           	   onDblClickCell:onDblClickCellFunc,
			   	   showFooter: true">
				<thead data-options="frozen:true">
					<tr>
						<th data-options="field:'inplanid',width:180,align:'right'">计划编号</th>
					</tr>
				</thead>
				<thead>
					<tr>
						<th data-options="field:'isprocess',width:90,align:'right',formatter:processFormatter">入库计划状态</th>
						<th data-options="field:'inplantype',width:90,align:'right',formatter:plantypeFormatter">入库计划类型</th>
						<th data-options="field:'operatorname',width:90,align:'right'">操作人员</th>
					</tr>
				</thead>
			</table>
		</div>
		<!-- 子表 -->
		<div data-options="region:'south'" title="HTTP服务信息测试	" style="width:100%;height:40%">
            <span hidden>inplanid</span>
            <table id="plandetail"
                   class="easyui-datagrid" ,
                   style="width:100%;height:99%;"
                   data-options="fit:true, rownumbers:true, pagination:false,singleSelect:true,fitColumns : 'true',method:'get'">
                <thead>
					<tr>
						<th data-options="field:'inplanid',width:180,align:'right'">入库计划编号</th>
						<th data-options="field:'status',width:90,align:'right',styler:cellStyler,formatter:detailProcessFormatter">处理状态</th>
						<th data-options="field:'materialssortsid',width:90,align:'right'">汽车品牌</th>
						<th data-options="field:'materialscode',width:90,align:'right'">系统车型</th>
						<th data-options="field:'materialscnname',width:90,align:'right'">中文名称</th>
						<th data-options="field:'materialsno',width:90,align:'right'">车架号</th>
						<th data-options="field:'materialscolor',width:90,align:'right'">颜色</th>
						<th data-options="field:'sellername',width:90,align:'right'">经销商</th>
						<th data-options="field:'startstaion',width:90,align:'right'">发站</th>
						<th data-options="field:'endstation',width:90,align:'right'">到站</th>
						<th data-options="field:'deliveryno',width:90,align:'right'">交接单号</th>
					</tr>
                </thead>
            </table>
		</div>
	</div>
</div>


<!-- 主表右键 -->
<div id="main-menu" class="easyui-menu" style="width:150px;">
    <div id="main-batch-operation" data-options="iconCls:'icon-import'">批量入库</div>
	<div class="menu-sep"></div>
    <div id="main-print" data-options="iconCls:'icon-print'">打印一维码</div>

</div>

<!-- 主表打印 -->
<div id="main-print-div" class="barcodeImg">

</div>

<!-- 子表右键 -->
<div id="menu" class="easyui-menu" style="width:150px;">
    <div id="m-operation-manu" data-options="iconCls:'icon-import'" >车辆自动入库</div>
    <div id="m-operation" data-options="iconCls:'icon-import'" >车辆手动入库</div>
	<div class="menu-sep"></div>
    <div id="m-print" data-options="iconCls:'icon-print'">打印一维码</div>
    <div id="m-print-2d" data-options="iconCls:'icon-print'">打印二维码</div>
</div>

<div id="printArea" class="barcodeImg"></div>
<div id="printArea2D"></div>
<img id="image" src="" />
<!-- 主表格式化 -->
<script type="text/javascript">
	 $(document).ready(function(){
		 $('#conent-layout').layout('collapse','south');
		 $('#conent-layout-detail').layout('collapse','east');
	 });
	//主表 处理状态格式化
	function processFormatter(val,row,index) {
		 var s = '';
		if(val=='0'){
			s = '未处理'
		}else if(val=='1'){
			s = '正在处理';
		}else if(val=='2'){
			s = '已处理';
		}
		return s;
	}
	//子表 明细 处理状态格式化
	 function cellStyler(value,row,index){
	 	if(value=='2'){
			return 'background-color:#ffee00;';
		}
	 }
	function detailProcessFormatter(val,row,index){
		var s = '';
		if(val=='2'){
			s = '已入库';
		}else if(val=='1'){
			s = '待入库';
		}
		return s;

	}
	function plantypeFormatter(val,row,index) {
		var s = '';
		if(val=='0'){
			s = '手工录入'
		}else if(val=='1'){
			s = 'Excel导入';
		}else if(val=='2'){
			s = '接收云仓计划'
		}
		return s;
	}

	function onDblClickCellFunc(rowIndex, row) {
		$("#conent-layout").layout('expand','south');
		var row = $('#tt').datagrid('getSelected');
		if(row){
			var url="<%=basePath%>/warehouse-manage-json/InPlanDetailEntity?INPLANID="+row.inplanid+"";
			$('#plandetail').datagrid('options').url = url;
			$('#plandetail').datagrid('reload');
		}
	}

	 $(function(){
		 var p = $('#tt').datagrid().datagrid('getPager');
		 p.pagination({
			 pageSize: 15, //每页显示的记录条数，默认为10
			 pageList: [15, 25, 35], //可以设置每页记录条数的列表
			 buttons : [ {
					 text : '删除计划',
					 iconCls:'icon-remove',
					 handler:function(){
						 var row = $('#tt').datagrid('getSelected');
						 if(!row){
							 $.messager.show({
								 title:'提示',
								 msg:'请选择需要删除的未处理入库计划 ',
								 timeout:3000,
								 showType:'slide',
							 });
						 }else if(row.isprocess!='0'){
							 $.messager.show({
								 title:'提示',
								 msg:'只有未处理的计划可以删除',
								 timeout:3000,
								 showType:'slide',
							 });
						 }else if(row.isprocess=='0'){
							 $.messager.confirm('删除信息','确定删除计划编号为:'+row.inplanid+"吗?",function(r){
								 if (r){
									 $.ajax({
										 url : '<%=basePath%>/delete-inwarehouse-plan-json',
										 data : {planid : row.inplanid},
										 async : true,
										 success : function(){
											 $('#tt').datagrid('reload');
											 $('#conent-layout').layout('collapse','south');
										 }
									 });
								 }
							 });
						 }
					 }
				 }
			 ],
			 onSelectPage: function (pageNumber, pageSize) {
				 var handler = '<%=basePath%>/warehouse-manage-json?entity=InPlanMainEntity&startCurr='+pageNumber+"&length="+pageSize;
				 $('#tt').datagrid('options').url = handler;
				 $('#tt').datagrid('reload');
			 }
		 });
	 });


</script>

<script>
    <!-- 主表设置右键菜单 -->
    $("#tt").datagrid({
        onRowContextMenu : function (e, rowIndex, rowData) {
            var row = $('#tt').datagrid('getSelected');
            if(row&&row.isprocess=='2'){
				e.preventDefault();
                $('#main-menu').menu('show',{
                    left : e.pageX,
                    top : e.pageY
                });
				$('#main-batch-operation').attr('disabled','disabled').css({"cursor": "default", "opacity": "0.4" });
				<!-- 主表批量入库解绑 -->
				$('#main-batch-operation').unbind();

            }else if(row&&row.isprocess!='2'){
				e.preventDefault();
				$('#main-menu').menu('show',{
					left : e.pageX,
					top : e.pageY
				});
				$('#main-batch-operation').removeAttr("disabled").css({ "cursor": "pointer", "opacity": "1" });
				<!-- 主表批量入库 -->
				$("#main-batch-operation").click(function () {
					alert('batch');
				});

			}else {
				e.preventDefault();
			}
        }
    });
    <!-- 主表一维码打印 -->
    $("#main-print").click(function(){
        var row = $('#tt').datagrid('getSelected');
        if(row){
            var planid = row.inplanid;
            $.ajax({
                type : 'post',
                url : '<%=basePath%>/warehouse-manage-json/InPlanDetailEntity?INPLANID='+planid+'',
                async : true,
                success : function(data){
                    for(var i=0;i<data.rows.length;i++){
                        var vin = data.rows[i].materialsno;
                        var div =$('<div id="t'+i+'"></div>');
                        div.empty().barcode(vin, "code128",{barWidth:2, barHeight:100,showHRI:true,moduleSize:10,posX:0,posY:0});
                        $("#main-print-div").append(div);
                    }
                    $("#main-print-div").jqprint({
                        importCSS: false
                    });
                },
                error : function(){
                    alert('error');
                }
            })
        }
    });


    <!-- 子表设置右键菜单 -->
    $("#plandetail").datagrid({
        onRowContextMenu : function(e, rowIndex, rowData){
            var row = $('#plandetail').datagrid('getSelected');
            if(row&&row.status=='2'){
				e.preventDefault();
                $('#menu').menu('show', {
                    left: e.pageX,         //弹出窗口的方位坐标
                    top: e.pageY
                });
				$('#m-operation-manu').attr('disabled','disabled').css({"cursor": "default", "opacity": "0.4" });
				$('#m-operation').attr('disabled','disabled').css({"cursor": "default", "opacity": "0.4" });
				$('#m-operation-manu').unbind();
				$('#m-operation').unbind();

            }else if(row&&row.status=='1'){
				e.preventDefault();
				$('#menu').menu('show', {
					left: e.pageX,         //弹出窗口的方位坐标
					top: e.pageY
				});
				$('#m-operation-manu').removeAttr("disabled").css({ "cursor": "pointer", "opacity": "1" });
				$('#m-operation').removeAttr("disabled").css({ "cursor": "pointer", "opacity": "1" });
				<!-- 子表自动入库 -->
				$('#m-operation-manu').click(function(){
					layer.msg('自动入库中', {
						time: 2000,
						icon: 1,
						success : function(){
							var row = $('#plandetail').datagrid('getSelected');
							if(row){
								//车架号
								var vin = row.materialsno;
								//司机
								var driver = 'BS300201';
								//入库状态
								var intype = '1';
								//操作人员
								var operator = 'cwarehouse';
								$.ajax({
									url : '<%=basePath%>/auto-in-warehouse',
									data : {vin : vin,driver:driver,intype:intype,operator:operator},
									async :true,
									type : 'post',
									error : function(){
										alert('入库失败');
									}

								})
							}else{

							}
						}
					});
				});
				<!-- 子表手工入库 -->
				$('#m-operation').click(function () {
					var info = '待入库库位:';
					layer.confirm(info, {
						btn: ['自动入库','手工入库'] //按钮
					}, function(){
						layer.msg('入库中', {
							time: 2000,
							icon: 1
						});
					}, function(){
						$('#conent-layout-detail').layout('expand','east');
					});
				});

            }else {
				e.preventDefault();
			}


        }
    });

    <!-- 子表一维码打印 -->
    $('#m-print').click(function () {
        var row = $('#plandetail').datagrid('getSelected');
        if(row){
            var vin = row.materialsno;
            $("#printArea").empty().barcode(vin, "code128",{barWidth:2, barHeight:100,showHRI:true});
            $("#printArea").jqprint({
                importCSS: false
            });

        }
    });

    <!-- 子表二维码打印 -->
    $('#m-print-2d').click(function(){
        var row = $('#plandetail').datagrid('getSelected');
        if(row){
            var vin = '';
            //车架号
            vin += row.materialsno;
            //汽车品牌
            vin += row.materialssortsid
            //系统车型
             vin += row.materialscode
            //颜色
             vin += row.materialscolor;
            //经销商
            $('#printArea2D').qrcode({
                render : 'canvas',
                width : 97,
                height : 97,
                text : toUtf8(vin)
            });

            var img = document.getElementById("image"); /// get image element
            var canvas  = document.getElementsByTagName("canvas")[0];  /// get canvas element
            img.src = canvas.toDataURL();
            $("#image").jqprint({
                importCSS: false
            });

        }
    });
    //识别中文
    function toUtf8(str) {
        var out, i, len, c;
        out = "";
        len = str.length;
        for(i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out += str.charAt(i);
            } else if (c > 0x07FF) {
                out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
                out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
            } else {
                out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
                out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
            }
        }
        return out;
    }
</script>
<!-- 格式化时间 -->
<script type="text/javascript">
	function myformatter(date){
		var y = date.getFullYear();
		var m = date.getMonth()+1;
		var d = date.getDate();
		return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
	}
	function myparser(s){
		if (!s) return new Date();
		var ss = (s.split('-'));
		var y = parseInt(ss[0],10);
		var m = parseInt(ss[1],10);
		var d = parseInt(ss[2],10);
		if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
			return new Date(y,m-1,d);
		} else {
			return new Date();
		}
	}
</script>




</body>
</html>